using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Principal;

namespace SmokeAlarm
{
    public partial class SmokinForm : Form
    {
        public SmokinForm(SmokeClient client)
        {
            InitializeComponent();
			smokerListBox.Items.Clear();
			m_client = client;
        }

		public void UpdateSmoker(string name, string status)
		{
			int foundIndex = -1;
			for (int i = 0; i < smokerListBox.Items.Count; ++i)
			{
				string smoker = (string)smokerListBox.Items[i];
				if (smoker.Contains(name))
				{
					foundIndex = i;
					break;
				}
			}
			if (foundIndex == -1)
			{
				smokerListBox.Items.Insert(smokerListBox.Items.Count == 0 ? 0 : smokerListBox.Items.Count - 1, name + " " + status);
			}
			else
			{
				smokerListBox.Items[foundIndex] = name + " " + status;
			}
		}

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

		// hellyeahButton
        private void button2_Click(object sender, EventArgs e)
		{
			string username = System.Windows.Forms.SystemInformation.UserName;
			m_client.SendRequest(username + "/yes");
        }

		// holdonButton
        private void button1_Click(object sender, EventArgs e)
        {
			string username = System.Windows.Forms.SystemInformation.UserName;
			m_client.SendRequest(username + "/holdon");
        }

        private void SmokinForm_Load(object sender, EventArgs e)
        {

        }

        public void UpdateRequestingSmokerLabel(string newText)
        {
            this.lblWhoIsSmoking.Text = newText;
        }
		// hellnoButton
		private void hellnoButton_Click(object sender, EventArgs e)
		{
			string username = System.Windows.Forms.SystemInformation.UserName;
			m_client.SendRequest(username + "/no");
		}

		private SmokeClient m_client;
    }
}